{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 07, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2> Probabilistic States </h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Suppose that Asja flips a fair coin secretly.\n",
    "\n",
    "Because we do not see the result, our information about the outcome will be probabilistic:\n",
    "\n",
    "$\\rightarrow$ The result is Head with probability $0.5$ and the result is Tail with probability $0.5$.\n",
    "\n",
    "If the coin has a bias $ \\dfrac{Pr(Head)}{Pr(Tail)} = \\dfrac{3}{1}$, then our information about the outcome is as follows:\n",
    "\n",
    "$\\rightarrow$  The result is Head with probability $ 0.75 $ and the result is Tail with probability $ 0.25 $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<i><u>Solution</u>: The probability of getting Head is three times of the probability of getting Tail.\n",
    "    <ul>\n",
    "        <li>The total probability is 1. </li>\n",
    "        <li> We divide 1 into four parts (three parts for Head and one part is for Tail),\n",
    "        <li> $ \\dfrac{1}{4} = 0.25$,</li>\n",
    "        <li> and then give three parts for Head ($0.75$) and one part for Tail ($0.25$).</li>\n",
    "    </ul></i>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Listing probabilities as a column </h3>\n",
    "\n",
    "We have two different outcomes: Head (0) and Tail (1).\n",
    "\n",
    "Then, we can use a column of size 2 to hold the probabilities of getting Head and getting Tail.\n",
    "\n",
    "For the fair coin, our information after the coin-flip is $ \\myvector{0.5 \\\\ 0.5} $. \n",
    "\n",
    "For the biased coin, it is $ \\myvector{0.75 \\\\ 0.25} $.\n",
    "\n",
    "The first entry refers to the probability of getting Head, and the second entry refers to the probability of getting Tail.\n",
    "\n",
    " $ \\myvector{0.5 \\\\ 0.5} $ and $ \\myvector{0.75 \\\\ 0.25} $ are examples of 2-dimensional (column) vectors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 1 </h3>\n",
    "\n",
    "Suppose that Balvis secretly flips a coin having bias $ \\dfrac{Pr(Head)}{Pr(Tail)} = \\dfrac{1}{4}$.\n",
    "\n",
    "Represent your information about the outcome as a column vector."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 2 </h3>\n",
    "\n",
    "Suppose that Fyodor secretly rolls a loaded (tricky) dice with the bias \n",
    "\n",
    "$$ Pr(1):Pr(2):Pr(3):Pr(4):Pr(5):Pr(6) = 7:5:4:2:6:1 . $$\n",
    "\n",
    "Represent your information on the result as a column vector. Remark that the size of your column should be 6.\n",
    "\n",
    "You may use python for your calculations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# You may use python for your calculations.\n",
    "#\n",
    "all_portions = [7,5,4,2,6,1];\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B32_Probabilistic_States_Solutions.ipynb#task2\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Vector representation </h3>\n",
    "\n",
    "Suppose that we have a system with 4 distiguishable states: $ s_1 $, $s_2 $, $s_3$, and $s_4$.  \n",
    "\n",
    "We expect the system to be in one of them at any moment. \n",
    "\n",
    "By using the language of probability, we can also say that the system is in one of the states with probability 1, and in any other state with probabilty 0. \n",
    "\n",
    "Then, by using our column representation, we can show each state as a column vector:\n",
    "\n",
    "$$\n",
    "    s_1 = \\myvector{1\\\\ 0 \\\\ 0 \\\\ 0}, s_2 = \\myvector{0 \\\\ 1 \\\\ 0 \\\\ 0}, s_3 = \\myvector{0 \\\\ 0 \\\\ 1 \\\\ 0}, \n",
    "    \\mbox{ and } s_4 = \\myvector{0 \\\\ 0 \\\\ 0 \\\\ 1}.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This representation helps us to represent our knowledge on a system when it is in more than one state with certain probabilities. \n",
    "\n",
    "Remember the case in which the coins are tossed secretly. \n",
    "\n",
    "For example, suppose that the system is in state $ s_1 $, $ s_2 $, $ s_3 $, and $ s_4 $ with probabilities $ 0.20 $, $ 0.25 $, $ 0.40 $, and $ 0.15 $, respectively. \n",
    "\n",
    "(<i>The total probability should be 1, i.e. $ 0.20+0.25+0.40+0.15 = 1.00 $</i>)\n",
    "\n",
    "Then, we can say that the system is in the following probabilistic state:\n",
    "$$\n",
    "    \\myvector{ 0.20 \\\\ 0.25 \\\\ 0.40 \\\\ 0.15 },\n",
    "$$\n",
    "where the summation of entries must be 1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b> Thus, we can show all information as a single object. </b>\n",
    "\n",
    "Nicely, <u>this probabilistic state</u> can also be written as the following summation:\n",
    "\n",
    "$$\n",
    "    0.20 \\cdot \\myvector{1\\\\ 0 \\\\ 0 \\\\ 0} + 0.25 \\cdot \\myvector{0\\\\ 1 \\\\ 0 \\\\ 0} + 0.40 \\cdot \\myvector{0\\\\ 0 \\\\ 1 \\\\ 0} + 0.15 \\cdot  \\myvector{0\\\\ 0 \\\\ 0 \\\\ 1} =     \\myvector{0.20\\\\ 0 \\\\ 0 \\\\ 0} +   \\myvector{0\\\\ 0.25 \\\\ 0 \\\\ 0} +  \\myvector{0\\\\ 0 \\\\0.40 \\\\ 0} +  \\myvector{0\\\\ 0 \\\\ 0 \\\\ 0.15 } = \\myvector{ 0.20 \\\\ 0.25 \\\\ 0.40 \\\\ 0.15 }.\n",
    "$$\n",
    "\n",
    "Here we use two basic arithmetic rules about the vectors:\n",
    "<ol>\n",
    "    <li> when a vector is multiplied with a number, then each entry of the vector is multiplied with this number, and, </li>\n",
    "    <li> when two or more vectors are added up, the summation is done on the same entries."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 3 </h3>\n",
    "\n",
    "Verify the following equality.\n",
    "\n",
    "$$\n",
    "    2 \\cdot \\mymatrix{r}{1\\\\-2\\\\3\\\\0} - 3 \\cdot \\mymatrix{r}{0\\\\4\\\\1\\\\-1} = \\mymatrix{r}{2 \\\\ -16 \\\\ 3 \\\\ 3}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 4 </h3>\n",
    "\n",
    "For a system with 4 states, randomly create a probabilistic state, and print its entries, e.g., $ 0.16~~0.17~~0.02~~0.65 $.\n",
    "\n",
    "You may pick your random numbers between 0 and 100 (or 1000), and then divide each by 100 (or 1000) to represent it as a probability."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from random import randrange\n",
    "\n",
    "#\n",
    "# your solution is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B32_Probabilistic_States_Solutions.ipynb#task4\">click for our solution</a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
